package bishi;

import java.util.*;

/**
 * @Author liuhaoqi
 * @Date 2020/9/3 20:11
 * @Version 1.0
 */
public class Baidu02 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int t = scanner.nextInt();
        int k = 0;
        int m = 0;
        int n = 0;
        int num = 0;
        for (int i = 0; i < t; i++) {
             n = scanner.nextInt();
             m = scanner.nextInt();
            int[] ints = new int[n];
            int[] ans = new int[n];
            for (int j = 0; j < ints.length; j++) {
                ints[j] = j + 1;
                ans[j] = 0;
            }

            ArrayList<Integer> list = new ArrayList<>();

            for (int j = 0; j < m; j++) {
                k= scanner.nextInt();
                for (int l = 0; l < k; l++) {
                    int left = scanner.nextInt();
                    int right = scanner.nextInt();
                    for (int o = left; o <= right; o++) {
                        ans[o-1] += 1;
                    }
                }
            }
            for (int l = 0; l < ans.length; l++) {
                if (ans[l] == m) {
                    num++;
                    list.add(l + 1);
                }
            }
            System.out.println(num);
            for (int l = 0; l < list.size(); l++) {
                System.out.print(list.get(l)+" ");
            }
        }
    }
}

